package br.com.webhomesites.locacao.presenter;

import br.com.webhomesites.locacao.model.EmpresaManutencaoDAO;
import br.com.webhomesites.locacao.model.ManutencaoDAO;
import br.com.webhomesites.locacao.view.BuscarManutencaoView;
import br.com.webhomesites.padrao.utils.Mascarador;
import java.awt.event.*;

public class BuscarManutencaoPresenterActionListeners {
    
    static class BuscarFocusListener implements FocusListener {
        
        private BuscarManutencaoPresenter presenter;
        private BuscarManutencaoView buscarManutencaoView;
        EmpresaManutencaoDAO empresaManutencaoDAO = new EmpresaManutencaoDAO();
        
        public BuscarFocusListener(BuscarManutencaoPresenter presenter) {
            this.presenter = presenter;
            buscarManutencaoView = presenter.getBuscarManutencaoView();
        }
        
        @Override
        public void focusGained(FocusEvent e) {
            ManutencaoDAO manutencaoDAO = new ManutencaoDAO();
            if (e.getSource() == presenter.getBuscarManutencaoView().getComboCodigoJCombo()) {
              
                    System.out.println("Falso");
                    buscarManutencaoView.setListaCodigo(manutencaoDAO.findAll());
                    buscarManutencaoView.setListaNome(empresaManutencaoDAO.findAll());
                    
                    presenter.setTipoBusca(presenter.POR_CODIGO_STRATEGY);
                
            } else if (e.getSource() == presenter.getBuscarManutencaoView().getComboNomeJCombo()) {
     
                presenter.setTipoBusca(presenter.POR_NOMECLIENTE_STRATEGY);
                
            } else if (e.getSource() == presenter.getBuscarManutencaoView().getDataInicialJTextField() || e.getSource() == presenter.getBuscarManutencaoView().getdataFinalJTextField()) {
     
                presenter.setTipoBusca(presenter.POR_DATASAIDA_STRATEGY);
                
            }
                    
        }
        
        @Override
        public void focusLost(FocusEvent e) {
            if (e.getSource() == presenter.getBuscarManutencaoView().getComboCodigoJCombo()) {
                
                //buscarManutencaoView.comboDescricaoRemoveAllItens();
                //buscarManutencaoView.comboSerieRemoveAllItens();
                
            } else if (e.getSource() == presenter.getBuscarManutencaoView().getComboNomeJCombo()) {
                
                //buscarManutencaoView.comboCodigoRemoveAllItens();
                //buscarManutencaoView.comboSerieRemoveAllItens();
                
            } else if (e.getSource() == presenter.getBuscarManutencaoView().getDataInicialJTextField()) {
                
                //buscarManutencaoView.comboCodigoRemoveAllItens();
                //buscarManutencaoView.comboDescricaoRemoveAllItens();
                
            }
        }
    }
    
    static class CampoKeyListener implements KeyListener {

        private BuscarManutencaoPresenter presenter;
        BuscarManutencaoView view;
        Mascarador mask;

        public CampoKeyListener(BuscarManutencaoPresenter presenter) {
            this.presenter = presenter;
            this.view = (BuscarManutencaoView) presenter.getBuscarManutencaoView();
            mask = new Mascarador();
        }

        @Override
        public void keyTyped(KeyEvent e) {
            //throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void keyPressed(KeyEvent e) {
            //throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void keyReleased(KeyEvent e) {
            view.setDataInicialSaida(mask.getMascara(view.getDataInicialSaida(), mask.DATA, e));
            view.setDataFinalSaida(mask.getMascara(view.getDataFinalSaida(), mask.DATA, e));  
            System.out.println("Colocando a máscara");
        }
    }
    
    static class BuscarActionListener implements ActionListener {
        
        private BuscarManutencaoPresenter presenter;
        
        public BuscarActionListener(BuscarManutencaoPresenter presenter) {
            this.presenter = presenter;            
        }
        
        @Override
        public void actionPerformed(ActionEvent e) {
            presenter.getTipoBusca().execute();            
            presenter.getBuscarManutencaoView().dispose();
        }
    }
    
    static class SairActionListener implements ActionListener {
        
        @Override
        public void actionPerformed(ActionEvent evt) {
            System.exit(0);
        }
    }
}
